<template>
	<view class="content">
		<!-- 我的绩效 -->
		<view class="fee-list">
			<view class="fee-item" v-for="(i,j) in list" :key="j">
				<view>
					<text>
						<text>主机：</text>
						<text>{{i.device}}</text>
					</text>
					<text>
						<text style="font-size: 32rpx; color: #39B54A;">+{{i.num}}</text>
					</text>
				</view>
				<view>
					<text>
						<text>保修类型：</text>
						<text>{{i.type}}</text>
					</text>
					<text style="color: #AAAAAA;">
						{{i.time}}
					</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import api from "../../../network/index.js"
	export default {
		data() {
			return {
				list: []
			};
		},
		methods:{
			// 查询关联单
			getlist(i){
				api.request({
					url: api.SERVICE_LIST_MEMBER,
					data: {
						user_id: "=,"+this.$store.state.user.userInfo.id
					}
				}).then(res=>{
					// console.log(res)
					if(res.data.list == "暂无数据")return this.list = []
					if(res.data.code == "200"){
						res.data.list.data.forEach(res=>{
							this.getDetail(res.order_service_id)
						})
					}else{
						// api.error(res)
					}
				}).catch()
			},
			getDetail(id){
				api.request({
					url: api.SERVICE_LIST,
					data:{
						id: "=,"+id
					}
				}).then(res=>{
					if(res.data.list == "暂无数据")return
					let data = res.data.list.data[0]
					console.log(data)
					// 获取打酱油字段
					let obj = {
						device: data.device.device_name, // 主机
						type: data.orderServiceType.title, // 维修类型
						time: data.create_time.slice(0,10), // 保修单创建时间
					}
					// 维保服务费
					let fee = data.service_fee;
					// 总数系数
					let allNum = 0; 
					data.orderServiceUser.forEach(res=>{
						allNum+=res.coefficient
					})
					// 我的系数
					let myNum = data.orderServiceUser.filter(i=>i.user_id==this.$store.state.user.userInfo.id)[0].coefficient; 
					
					obj.num = (myNum/allNum*fee).toFixed(2)
					
					this.list.push(obj)					
					
				}).catch()
			}
		},
		onLoad(options) {
			this.getlist()
		}
	}
</script>

<style lang="scss" scoped>
.fee-list{
	margin: 0 20rpx;
	.fee-item{
		margin: 20rpx 0;
		background-color: #FFFFFF;
		box-shadow: 4rpx 4rpx 8rpx #EEEEEE;
		view{
			display: flex;
			justify-content: space-between;
			padding: 20rpx;
			line-height: 44rpx;
		}
	}
}
</style>
